﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Entity;
using Utility;

namespace StudentAppointmentPlatform.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterHyperLink.NavigateUrl = "Register.aspx";
        }

        protected void LoginButton_OnClick(object sender, EventArgs e)
        {
            User findUser = UserBO.GetUserByUserName(UserName.Text);

            string loginType = string.Empty;
            if (RB_Stu.Checked)
            {
                loginType = "Student";
            }
            else if(RB_Dir.Checked)
            {
                loginType = "Director";
            }

            if (findUser.UserName == UserName.Text && findUser.Password == Password.Text && findUser.Type == loginType)
            {
                Session["UserId"] = findUser.UserId;
                Session["UserName"] = findUser.UserName;
                Session["LoginType"] = loginType;

                Alert.AlertOnPage(Page, "登录成功，将为您跳转到默认页面。");
                Redirect.Js_Redirect(Page, "/Default.aspx");
            }
            else
            {
                Alert.AlertOnPage(Page, "用户名或密码错误，或者选错了登录类型，请重新登录。");
            }
        }
    }
}
